/**
 * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.api.common;

import com.fasterxml.jackson.annotation.JsonIgnore;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;


/**
 * $.ajax后需要接受的JSON
 * 
 * @author
 * 
 */
public class ResJson extends HashMap<String,Object> implements Serializable {
	private static final long serialVersionUID = 1L;

	public ResJson() {
		this.put("result", "0");
		this.put("resultNote", "请求成功");
	}

	@JsonIgnore//返回对象时忽略此属性
	public static ResJson success() {
		ResJson res = new ResJson();
		return res;
	}
	
	@JsonIgnore//返回对象时忽略此属性
	public static ResJson success(String msg) {
		ResJson res = new ResJson();
		res.setResultNote(msg);
		return res;
	}
	
	@JsonIgnore//返回对象时忽略此属性
	public static ResJson error(String msg) {
		ResJson res = new ResJson();
		res.setResult("1");
		res.setResultNote(msg);
		return res;
	}
	
	/**
	 * 总条数
	 * @param totalCount
	 */
	@JsonIgnore//返回对象时忽略此属性
	public ResJson setTotalCount(long totalCount) {
		this.put("totalCount", totalCount);
		return this;
	}

	/**
	 * 状态 0 成功 1 失败
	 * @param result
	 */
	@JsonIgnore//返回对象时忽略此属性
	public ResJson setResult(String result) {
		this.put("result", result);
		return this;
	}

	/**
	 * 总页数
	 * @param totalPage
	 */
	@JsonIgnore//返回对象时忽略此属性
	public ResJson setTotalPage(int totalPage) {
		this.put("totalPage", totalPage);
		return this;
	}

	/**
	 * 提示语
	 * @param resultNote
	 */
	@JsonIgnore//返回对象时忽略此属性
	public ResJson setResultNote(String resultNote) {
		this.put("resultNote", resultNote);
		return this;
	}

	/**
	 * 数据列表
	 * @param <T>
	 * @param dataList
	 */
	@JsonIgnore//返回对象时忽略此属性
	public <T> ResJson setDataList(List<T> dataList) {
		this.put("dataList", dataList);
		return this;
	}
	
	@JsonIgnore//返回对象时忽略此属性
	public ResJson put(String key, Object value) {
		super.put(key, value);
		return this;
	}
}
